package com.yonyou.rabbitmq.receiver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
public class WorkerReceiver {

    @RabbitListener(queuesToDeclare = @Queue("workerQueue"))
    @RabbitHandler
    public void receiveMessage(Message message) throws InterruptedException {
        try {
            Jackson2JsonMessageConverter jackson2JsonMessageConverter =new Jackson2JsonMessageConverter();
            final Object message1 = jackson2JsonMessageConverter.fromMessage(message);
            System.out.println("WorkerReceiver1接收到消息：" + message1);
        }catch (Exception e){
            log.info("get order fromBytes message exception"+e.getMessage());
        }
        Thread.sleep(3L);
    }

}
